package com.baidu.demo;

import cn.hutool.json.JSONUtil;
import com.baidu.entity.User;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo04 {
    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<>();
        User user = new User();
        user.setId(1);
        user.setUsername("zhangsan");
        user.setCreatedAt(LocalDateTime.now());

        User user2 = new User();
        user2.setId(1);
        user2.setUsername("zhangsan");
        user2.setCreatedAt(LocalDateTime.now());

        //把它装进一个集合里
        List<User> userList = new ArrayList<>();
        userList.add(user);
        userList.add(user2);
        map.put("code", 0);
        map.put("data", userList);
        String jsonStr = JSONUtil.toJsonStr(map);
        System.out.println(jsonStr);

    }
}
